﻿using System;

namespace LD
{
    public partial class FrmAlertHis : FrmBase
    {
        private ReDrawUI ReDrawUI = new ReDrawUI();
        public FrmAlertHis()
        {
            InitializeComponent();
            LogHelper.Instance.LogEvent += LogEvent;
        }

        private void FrmAlert_Load(object sender, EventArgs e)
        {
            this.Resize += new EventHandler(FrmAlert_Resize);
            //ReDrawUI.ControlInitializeSize(this);

            dtStart.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
            dtEnd.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
            CreateUI();

            //if (Cache.GetCache(CONST.BC_SOUND) == null)
            //    Cache.SetCache(CONST.BC_SOUND, true);
            //if (Cache.GetCache(CONST.BC_DOOR) == null)
            //    Cache.SetCache(CONST.BC_DOOR, true);

            //btnSound.BackColor = (bool)Cache.GetCache(CONST.BC_SOUND) ? Color.Green : Color.Red;
            //btnSound.Text = (bool)Cache.GetCache(CONST.BC_SOUND) ? "蜂鸣打开中" : "蜂鸣关闭中";
            //btnDoor.BackColor = (bool)Cache.GetCache(CONST.BC_DOOR) ? Color.Green : Color.Red;
            //btnSound.Text = (bool)Cache.GetCache(CONST.BC_DOOR) ? "安全门启用中" : "安全门禁用中";
        }
        private void FrmAlert_Resize(object sender, EventArgs e)
        {
            ReDrawUI.ControlAutoSize(this);
        }

        private void LogEvent(string content, LogLevel type)
        {
        }

        private void btn_today_Click(object sender, EventArgs e)
        {
            dtStart.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 00:00:00"));
            dtEnd.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd 23:59:59"));
            Search();
        }

        private void btn_preDay_Click(object sender, EventArgs e)
        {
            dtStart.Value = dtStart.Value.AddDays(-1);
            dtEnd.Value = dtEnd.Value.AddDays(-1);
            Search();
        }

        private void btn_nextDay_Click(object sender, EventArgs e)
        {
            dtStart.Value = dtStart.Value.AddDays(1);
            dtEnd.Value = dtEnd.Value.AddDays(1);
            Search();
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
            Search();
        }
     
        private void Search()
        {
            var list = DBHelper.Instance.Sql.Queryable<TB_Alarm>()
                  .Where(p => p.CreateTime >= dtStart.Value && p.CreateTime <= dtEnd.Value)
                  .ToList();

            this.dgv_collect.DataSource = list;
        }
        private void CreateUI()
        {
          
        }
    }
}
